package com.cat.controller;

import com.cat.pojo.Admin;
import com.cat.pojo.Carlist;
import com.cat.service.AdminService;
import com.cat.service.CarService;
import com.cat.util.LayUI;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Controller
public class CarController {
    @Resource
    private CarService carService;
    @PostMapping("/admin/assNewCar")
    @ResponseBody
    public boolean addNewCar(@RequestBody Carlist carlist){
        System.out.println(carlist);
        return carService.addNewCar(carlist);

    }
    @PostMapping("/admin/gatCarByCid/{c_id}")
    @ResponseBody
    public Carlist gatCarById(@PathVariable("c_id") int c_id){
//        System.out.println(id);
//        int c_id=(int)id;
        System.out.println(c_id);
        return carService.getCarById(c_id);

    }
    @PutMapping("/admin/updateCar")
    @ResponseBody
    public boolean updateCar(@RequestBody Carlist carlist){
        return  carService.updateCar(carlist);
    }

    @DeleteMapping("/admin/deleteByCid/{c_id}")
    @ResponseBody
    public boolean deleteByCid(@PathVariable("c_id") int c_id){
        System.out.println(c_id);
       return carService.deleteByCid(c_id);
    }


    @GetMapping("/admin/getallcar")
    @ResponseBody
    public LayUI login(){

        LayUI lu=new LayUI();

        lu.setCode(0);
        lu.setMsg("");
        lu.setData(carService.getAllCar());

        return lu;

    }
}
